#!/bin/bash

cmd=$1
arg="-l"

case $cmd in
   "start")
       arg="-s"
       ;;
   "stop")
       arg="-S"
       ;;
   *)
       echo "Ukonwn option, ignoring ..."
       exit 1
       ;;
esac

# if we just start daemon, wiat a seconds before connect to server
if [ "$arg" == "-s" ]; then
	sleep 5
fi

TR_ID=/tmp/tr.id

transmission-remote -n "hitmoon:Mytm0008" -l | awk '/^ *[0-9]+ / {print $1}' > $TR_ID

while read t
do
echo "stoping torrent $t ..."
transmission-remote -n "hitmoon:Mytm0008" -t $t $arg

done < $TR_ID

rm -f $TR_ID
